﻿using System.Collections.Generic;
using System.Globalization;
using System.IO;
using RayDen.Library.Core.Primitives;

namespace RayDen.Library.Data
{
    public class SPDFile
    {

        public SampledSpectrum Open(string fileName, SpectrumType st)
        {
            using (TextReader tr = new StringReader(fileName))
            {

                List<float> lambda = new List<float>(), sample = new List<float>();
                while (true)
                {
                    var line = tr.ReadLine();
                    if (line == null)
                        break;
                    if (line.Contains("#"))
                        continue;
                    var data = line.Split(' ');
                    lambda.Add(float.Parse(data[0], NumberStyles.Any, CultureInfo.InvariantCulture));
                    sample.Add(float.Parse(data[1], NumberStyles.Any, CultureInfo.InvariantCulture));
                }
                return SampledSpectrum.FromSampled(lambda.ToArray(), sample.ToArray(), st);
            }
        }

    }
}